import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' //https://github.com/vbenjs/vite-plugin-svg-icons/blob/main/README.zh_CN.md
import removeConsole from 'vite-plugin-remove-console';
export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'src/preload/index.ts'),
          secondscreen: resolve(__dirname, 'src/preload/secondscreen.ts')
        }
      }
    },
    plugins: [
      externalizeDepsPlugin()
      
    ]
  },
  renderer: {
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'src/renderer/index.html'),
          secondscreen: resolve(__dirname, 'src/renderer/secondscreen.html')
        }
      }
    },
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [removeConsole(),vue(),createSvgIconsPlugin({

      // 指定需要缓存的图标文件夹
      iconDirs: [resolve(process.cwd(), 'src/renderer/src/assets/svg')],
      // 指定symbolId格式
      symbolId: 'icon-[dir]-[name]',
    
    }),],
    
    css: {
      preprocessorOptions: {
        scss: { api: 'modern-compiler' },
      }
    },
    server: {
      // 代理规则
      "proxy": {
        '/api': {
          // 目标服务器地址
          // http://192.168.22.208:8081
          target: 'http://39.101.143.18:8081',
          // 是否改变请求的origin（用于解决跨域问题）
          changeOrigin: true,
          // 请求路径重写规则
          rewrite: p =>p.replace(/^\/api/,'')
        },
        
        }
      
    },

  },
  
})
